<script language="javascript" type="text/javascript" src="/assets/My97DatePicker/jquery-1.8.2.js"></script>
<script language="javascript" type="text/javascript" src="/assets/libs/fastadmin-layer/dist/layer.js"></script>
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="" enctype="multipart/form-data">

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">总金额:</label>
        <div class="col-xs-12 col-sm-8" style="width:410px;">
            <span>{$orderRes.payprice}</span>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">剩余金额:</label>
        <div class="col-xs-12 col-sm-8" style="width:410px;">
            <span id="remain"> {$orderRes.payprice}</span>
        </div>
    </div>

    {volist name="arr" id="vo"}
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">第{$vo.number_id}期:</label>
            <div class="col-xs-12 col-sm-8" style="width:410px;">
                <input oninput="changeprice(this)"  class="form-control"  name="{$vo.number_id}"  id="number_id{$vo.number_id}" type="number"  min="0" value=""  arr_id="1">
            </div>
        </div>
    {/volist}


    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="button" class="btn btn-success btn-embossed" onclick="sub();">添加</button>
            <a  href="" class="btn btn-default btn-embossed">返回</a>
        </div>
    </div>
</form>

<script language="JavaScript">
    var money="{$orderRes.payprice}";
    var number="{$number}";

function changeprice(obj){
   var othertotalprice=0
    for(var i=1;i<parseInt(number)+1;i++){
        if($(obj).attr("id")!="number_id"+i){
            othertotalprice=Number($("#number_id"+i).val())+othertotalprice
        }
    }
    var totalprice=0
    totalprice=othertotalprice+Number($(obj).val());

    if(totalprice>money){
        $(obj).val(money-othertotalprice);
        totalprice=money;
    }
  var remain=money-totalprice;
    $("#remain").html(remain);

}










    function sub() {
        var get_remian=Number($("#remain").text());
        if(get_remian>0){
            layer.alert("数据分配不合理");
            return false;
        }

        var arr=$("input[arr_id='1']");
        $(arr).each(function(){
            var val= $(this).val();
            if(val==0){
                layer.alert("数据不得为空");
                return false;
            }
        });
        $("#add-form").submit();

    }

</script>



